# 导入的包
from core import src
from conf import settings
import os


# 输入用户名
def pass_name():
    while True:
        name = input("请输入你的用户名(只能含有字母或者数字)：")
        for i in name:
            if name.isdecimal() or 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122:
                break
        else:
            print('用戶名格式錯誤,請重新輸入')
            continue
        return name


# 输入密码
def pass_word():
    while True:
        word = input("请输入你的密码(长度要在6~14个字符之间)：")
        if 6 <= len(word) <= 14:
            return word
        else:
            print('密碼格式錯誤')


# 装饰器
def wrapper(f):
    def inner():
        if src.entercg_dic["flag"]:
            f()
        else:
            src.enter()
            if src.entercg_dic["flag"]:
                f()
    return inner


# 日志的准备
def get_logger():
    path = os.path.join(settings.BASE_PATH, "log", f"{src.entercg_dic['name']}.log")
    settings.LOGGING_DIC['handlers']['file']['filename'] = path
    settings.logging.config.dictConfig(settings.LOGGING_DIC)  # 导入上面定义的logging配置
    logger = settings.logging.getLogger(__name__)  # 生成一个log实例
    return logger


# 日志传入
def all_log(f):
    logger = get_logger()
    logger.info(f)  # 记录该文件的运行状态


# 日志的转账其他人
def transfer2(name1, name2, money):
    path = os.path.join(settings.BASE_PATH, "log", f"{name2}.log")
    settings.LOGGING_DIC['handlers']['file']['filename'] = path
    settings.logging.config.dictConfig(settings.LOGGING_DIC)  # 导入上面定义的logging配置
    logger = settings.logging.getLogger(__name__)  # 生成一个log实例
    logger.info(f'{name1}转账给我{money}元！')  # 记录该文件的运行状态



